package com.mingqi.enetconnected.view.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;

import com.mingqi.enetconnected.R;
import com.mingqi.enetconnected.util.resource.ResourceUtils;
import com.uuzuche.lib_zxing.activity.CodeUtils;

/**
 * @author li
 * @version 1.0
 * @describe
 * @WeChat 18571658038
 * @date 2018/9/14 星期五.
 */

public class QrCodeDialog extends Dialog {

    private ImageView mIvDismiss;
    private ImageView mIvQrCode;
    private Bitmap mBitmap;
    private String mQrMsg;

    public QrCodeDialog(@NonNull Context context,String qrMsg) {
        this(context,R.style.MyBaseDialog);
        mQrMsg = qrMsg;
    }

    public QrCodeDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dialog_qr_code);

        mIvDismiss = findViewById(R.id.iv_dismiss);
        mIvQrCode = findViewById(R.id.iv_qr_code);

        mIvDismiss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dismiss();
            }
        });

        int dimenWidth = ResourceUtils.getDimen(R.dimen.x160);
        int dimenHeight = ResourceUtils.getDimen(R.dimen.y160);
        mBitmap = CodeUtils.createImage(mQrMsg, dimenWidth, dimenHeight, null);
        mIvQrCode.setImageBitmap(mBitmap);
    }


}
